package com.itheima.annotation.anno3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class AnnoDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // 1. 通过反射回去UseTest类的字节码文件对象
        Class<?> clazz = Class.forName("com.itheima.annotation.anno3.UseTest");
        // 创建对象
        UseTest useTest = (UseTest) clazz.getConstructor().newInstance();
        // 2. 通过反射获取这个类中所有的方法对象
        Method[] methods = clazz.getDeclaredMethods();
        // 3. 遍历数组得到每一个方法对象
        for (Method method : methods) {
            boolean annotationPresent = method.isAnnotationPresent(Test.class);
            if (annotationPresent) {
                method.invoke(useTest);
            }
        }
    }
}
